#coding=utf-8

from django.shortcuts import render
from django.shortcuts import render_to_response,HttpResponseRedirect,HttpResponse
from django.template.loader import get_template
from django.template import Context
import json
from fanli.models import monitor

def fanli(request):
    return render_to_response('fanli.html')

def fanli_db_size(request):
    u = monitor()
    tablesize = u.get_tablesize()
    return render_to_response('fanli_db_size.html',{'tablesize':tablesize})

def fanli_user_funnel(request):
    return render_to_response('fanli_user_funnel.html')

def fanli_json_get_db_size(request):
    u = monitor()
    g_data = u.get_db_size()
    xx=[]
    yy01=[]
    yy02=[]
    dic={}
    for obj in g_data:
        xx.append(obj[0])
        yy01.append(obj[1])
        yy02.append(obj[2])

    dic['dt']=xx
    dic['free_siz_min']=yy01
    dic['free_siz_max']=yy02

    return HttpResponse(json.dumps(dic))

def fanli_json_get_user_funnel(request):
    u = monitor()
    g_data = u.get_user_funnel()
    dic={}
    for obj in g_data:
        yy01 = obj[0]
        yy02 = obj[1]
        yy03 = obj[2]
    dic['access_uv']=yy01
    dic['goshop_uv']=yy02
    dic['buy_user_cnt']=yy03
    return HttpResponse(json.dumps(dic))
